package com.ambulance.project.manager.utils;

import com.ambulance.common.utils.ServletUtils;
import com.ambulance.framework.security.LoginUser;
import com.ambulance.framework.security.service.TokenService;
import com.ambulance.utils.CommonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/***
 *  @description 管理平台登陆后获取登陆者信息
 *  @author zhao
 *  @date: 2020/5/12
 *  @version: v1.0
 */
@Component(value = "mgtCommonUtil")
public class MgtCommonUtil {

    @Autowired
    private TokenService tokenService;

    public MgtUserLoginResult getMgtUserLoginResult() {
        MgtUserLoginResult loginResult = new MgtUserLoginResult();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        loginResult.setUid(loginUser.getUser().getUserId().intValue());
        if(!CommonUtils.checkNull(loginUser.getUser().getRoles()) && loginUser.getUser().getRoles().get(0).getRoleId().equals(100L)){
            loginResult.setUid(1);
        }
        loginResult.setHospitalName(loginUser.getUser().getNickName());
        return loginResult;
    }
}
